/* $RCSFile: ADNDynSubject.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/CRMWrapper3/DynEntities/ADNDynSubject.cs $
 * $log$
 * Revision 19 2010/10/02 14:01:49  christian.surieux
 *   Corrected a bug in allmost everyADNDyn file for PrimaryFieldVualue
 * Revision 6 2010/08/06 19:56:33  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using CrmSdk;

namespace AddonNice.CRMWrapper
{
	public class ADNDynSubject : DynEntity
	{
        protected class Ftor: DFactor
        {
            public Ftor() : base(CrmStr.subject)
            {}

            public override Type DynType
            { get { return typeof(ADNDynSubject); } }

            public override string DynTypename
            {   get{ return CrmStr.subject;}}

            public override DynEntity Build()
            {   return new ADNDynSubject();}

            public override DynEntity Build(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection wproperties)
            {   return new ADNDynSubject(w, dEntity, wproperties, null);}

            public override DynEntity Build(CRMWrapperBase w, string PrimaryFieldValue)
            {   return new ADNDynSubject(w, PrimaryFieldValue);}

            public override DynEntity Build(CRMWrapperBase w,Guid PrimaryKeyValue)
            {   return new ADNDynSubject(w,PrimaryKeyValue);}
        }

        static ADNDynSubject(){new Ftor();} 

        public override bool HasOwnerProperty
        {
            get
            {
                return false;
            }
        }

        public override bool HasBusinessUnitProperty
        {
            get
            {
                return false;
            }
        }

        public ADNDynSubject(): base()
		{}

        public ADNDynSubject(CRMWrapperBase w, string PrimaryFiedlValue)
			: base(w,CrmStr.subject)
		{
            if ( PrimaryFiedlValue != string.Empty )
                title    =   PrimaryFiedlValue;
		}

		public ADNDynSubject(CRMWrapperBase w, Guid CrmId)
			: base(w,CrmStr.subject, CrmId)
		{}

		public ADNDynSubject(CRMWrapperBase w, InternalDynamicEntity e)
			: base(w,CrmStr.subject,e,null,null)
		{}

		public ADNDynSubject(CRMWrapperBase w, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(w,CrmStr.subject,e,prop,s)
		{}

        public ADNDynSubject(ResetWrapperHandler fn, string PrimaryFiedlValue)
			: base(fn,CrmStr.subject)
		{
            if ( PrimaryFiedlValue != string.Empty )
                title    =   PrimaryFiedlValue;
		}

		public ADNDynSubject(ResetWrapperHandler fn, Guid CrmId)
			: base(fn,CrmStr.subject, CrmId)
		{}

		public ADNDynSubject(ResetWrapperHandler fn, InternalDynamicEntity e)
			: base(fn,CrmStr.subject,e,null,null)
		{}

		public ADNDynSubject(ResetWrapperHandler fn, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(fn,CrmStr.subject,e,prop,s)
		{}

		/// <summary>
		/// Crm Key
		/// </summary>
        [CrmDynAttribute(CrmStr.subject)]
        public Guid subjectid
		{
			get
			{
				return KeyPropertyValue(CrmStr.subjectid);
			}
			set
			{
				AddKeyProperty(CrmStr.subjectid, value);
			}
		}

        protected override void SetCrmIdProperty(Guid crmId)
        {
           if ( !dicProperty.ContainsKey(CrmStr.subjectid) || KeyPropertyValue(CrmStr.subjectid) != crmId )
                subjectid   =   crmId;
        }
        
        public override string PrimaryFieldName
        {
            get
            {
               return CrmStr.title;
            }
           set
           {}
        }

        /// <summary>
        /// Value contained in the PrimaryField for the DynEntity or empty if no PrimaryField
        /// </summary>
        public override string PrimaryFieldStringValue
        {
            get
            {
                return title;
            }
            set
            {
                title =   value;
            }
        }

        public override Guid PrimaryKeyGuidValue
        {
           get
           {
                return subjectid;
           }
           set
           {
               subjectid    =   value;
           }
        }

        /// <summary>
        /// Gets or sets the title of the subject. 
        /// </summary>
        [CrmDynAttribute(CrmStr.subject)]
        public string title 
        {
            get
            {
                return StringPropertyValue(CrmStr.title);
            }
            set
            {
                AddStringProperty(CrmStr.title,value);
            }
        }

        /// <summary>
        /// Contains the description of the subject. 
        /// </summary>
        [CrmDynAttribute(CrmStr.subject)]
        public string description 
        {
            get
            {
                return StringPropertyValue(CrmStr.description);
            }
            set
            {
                AddStringProperty(CrmStr.description,value);
            }
        }

        /// <summary>
        /// Gets or sets the ID of the parent subject. 
        /// </summary>
        [CrmDynAttribute(CrmStr.subject)]
        public Guid parentsubject
        {
            get
            {
                if (ContainsKey(CrmStr.parentsubject))
                    return LookupPropertyValue(CrmStr.parentsubject);
                return Guid.Empty;
            }
            set
            {
                AddLookupProperty(CrmStr.parentsubject,CrmStr.subject,value);
            }
        }

        public string parentsubjectName
        {
            get
            {
                if (ContainsKey(CrmStr.parentsubject))
                    return LookupPropertyName(CrmStr.parentsubject);
                return string.Empty;
            }
        }
        
        /// <summary>
        /// Gets or sets when the subject will be displayed in lists of subjects. 
        /// </summary>
        [CrmDynAttribute(CrmStr.subject)]
        public int featuremask
        {
            get
            {
                if ( ContainsKey(CrmStr.featuremask) )
                    return NumberPropertyValue(CrmStr.featuremask);
                return 0;
            }
            set
            {
                AddNumberProperty(CrmStr.featuremask,value);
            }
        }
	}
}
